package com.mktech.taraservicelib.http;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.mktech.taraservicelib.util.LogTool;


public class HttpBuilder
{
	public static String DEFAULT_HOST = "203.115.192.52:80";
	public static String DEFAULT_DOMAIN = "http://" + DEFAULT_HOST + "/tara-china-new/";
	public static String API = "api/v1/";
	
	public static String USER_LOGIN = API + "user/login";
	public static String USER_SOCIAL_LOGIN = API + "user/social";
	public static String USER_LOGOUT = API + "user/logout";
	public static String USER_FORGOT_PW = API + "user/forgot";
	public static String USER_REGISTER = API + "user/register";
	public static String HOME_FETCH = API + "home/fetch";
	public static String CONTENT_LANGUAGE = API + "language/index";
	
	public static String append(String str)
	{
		StringBuilder builder = new StringBuilder(DEFAULT_DOMAIN);
		builder.append(str);
		return builder.toString();
	}
	
	public static boolean appendApi(StringBuilder builder, Map<String, String> map)
	{
		if(builder == null || map == null)
			return false;
		Set<String> keySet = map.keySet();
		if(keySet.size() == 0)
			return false;
		
		char lastChar = builder.charAt(builder.length() - 1);
		if(lastChar != '?')
		{
			builder.append('?');
		}
		
		for(Iterator<String> i = keySet.iterator(); i.hasNext();)
		{
			String key = i.next();
			String value = map.get(key);
			builder.append(key + "=" + value + "&");
		}
		builder.deleteCharAt(builder.length() - 1);
		LogTool.i(builder.toString());
		
		return true;
	}
}
